package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.BaseModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.OrderInforView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/7/27.
 */

public class UseSurplusPresenter extends BasePresenter {
    Context context;

    OrderInforView view;
    public UseSurplusPresenter(Context comtext,OrderInforView view)
    {
        this.context=comtext;
        this.view=view;
    }

    public void LoadSurolus(String pwd,String surplus,String order_id)
    {
        Map<String,String > params=new HashMap<String,String>();
        params.put("key", ConfigValue.DATA_KEY);
        params.put("pwd",pwd);
        params.put("surplus",surplus);
        params.put("order_id",order_id);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "order/useSurplus", params, new BaseDelegate.ResultCallback<BaseModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                Utils.showToast(context, ExceptionHelper.getMessage(e,context));
            }

            @Override
            public void onResponse(BaseModel response, Object tag) {
                view.changeIntegral(response);
            }


        });
    }
}
